<?php
/**
 * 节点管理模型层
 *
 */
class NodeModel extends Model {
	
	/**
	 * 节点列表
	 *
	 * @param bool $showMenu
	 * @param bool $showgarend
	 * @return array
	 */
	function nodeList($showMenu = false, $showgarend = true) {
		if ( $showMenu ) {
			$sql = " AND `is_menu`=1 AND `is_show`=1";
		}else $sql = "";
		$parentNode = $this->where ( "`parent`=0" . $sql )->order ( "`sort` ASC" )->findAll ();
		foreach ( $parentNode as $key => $pn ) {
			$childNode = $this->where ( "`parent`=" . $pn ["id"] . $sql )->order ( "`sort` ASC" )->findAll ();
			$parentNode [$key] ['child'] = $childNode;
			if ( $showgarend ) {
				foreach ( $childNode as $k => $cn ) {
					$gchildNode = $this->where ( "`parent`=" . $cn ["id"] . $sql )->order ( "`sort` ASC" )->findAll ();
					$parentNode [$key] ['child'] [$k] ['child'] = $gchildNode;
				}
			}
		}
		return $parentNode;
	}
}
?>